package com.aabte.springcloudlearn.feigncustomerdemo.controller;

import com.aabte.springcloudlearn.feigncustomerdemo.service.HelloCustomerServiceFeign;
import com.aabte.springcloudlearn.feigncustomerdemo.service.RefactorHelloCustomerFeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Daniel
 */
@Slf4j
@RestController
@RequestMapping("/feign")
public class HelloCustomerController {

    @Autowired
    private HelloCustomerServiceFeign helloCustomerServiceFeign;

    @GetMapping("/hello")
    public String sayHello() {
        log.info("Start sayHello.");
        String result = helloCustomerServiceFeign.helloFeign();
        log.info("End sayHello. result: {}", result);
        return result;
    }

    @Autowired
    private RefactorHelloCustomerFeignService refactorHelloCustomerFeignService;

    @GetMapping(value = "/refactor/{name}")
    public String refactorHelloService(@PathVariable String name){
        log.info("Start refactorHelloService. name: {}", name);
        String result = refactorHelloCustomerFeignService.hello(name);
        log.info("End refactorHelloService. result: {}", result);
        return result;
    }

}
